package com.woniu.client;

import com.woniu.dto.AccountDto;
import com.woniu.dto.AccountRoleDto;
import com.woniu.dto.RoleDto;
import com.woniu.form.AddAccountForm;
import com.woniu.form.AddAccountRoleForm;
import com.woniu.form.AddUserAccountForm;
import com.woniu.model.Result;
import io.seata.spring.annotation.GlobalTransactional;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * 该类用于调用 Permissions 服务的资源
 */
@FeignClient(name = "permissions-server",path = "/permissions")
public interface PermissionsClient {

    /**
     * 新增用户账号
     * @param form
     * @return
     */
    @ApiOperation("新增用户账号")
    @PostMapping("/account/addUserAccount")
    public Result<AccountDto> addUserAccount(@RequestBody AddUserAccountForm form);

    /**
     * 新增账号角色关联
     * @param form 账号id 角色id
     * @return
     */
    @ApiOperation("新增账号角色关联")
    @PostMapping("/accountRole/addAccountRole")
    public Result<AccountRoleDto> addAccountRole(@RequestBody AddAccountRoleForm form);

    /**
     * 根据账号查询角色
     * @param accountId 账号id
     * @return
     */
    @ApiOperation("根据账号id查询角色")
    @GetMapping("/accountRole/selectRoleByAccountId/{accountId}")
    public Result<RoleDto> selectRoleByAccountId(
            @PathVariable("accountId")
            @ApiParam(name = "accountId",value = "账号id")
            String accountId
    );

    /**
     * 根据手机号 或者 用户名查询 账号列表
     * @param phone
     * @return
     */
    @GetMapping("/account/byPhoneOrUsername/{phone}/{accountName}")
    @ApiOperation("根据手机号或者用户名查询账号列表")
    public Result<List<AccountDto>> byPhoneOrUsername(@PathVariable("phone") String phone, @PathVariable("accountName") String accountName);

    /**
     * 根据用户名查询 账号对象
     * @param phone
     * @return
     */
    @GetMapping("/account/byPhone/{phone}")
    public Result<AccountDto> byPhone(@PathVariable("phone") String phone);

    /**
     * 修改用户密码
     * @param accountId 账号id
     * @param newPassword 新密码
     * @return
     */
    @GetMapping("/account/modifyUserPass/{accountId}/{newPassword}")
    public Result<?> modifyUserPass(@PathVariable("accountId") Integer accountId,@PathVariable("newPassword") String newPassword);
}
